#ifndef MYMATH_H
#define MYMATH_H
#include <QByteArray>
#include <QtMath>
class MyMath
{
public:
    MyMath();
    void FloatTo4Bytes(float f_temp,char *chr);
    float FourBytesToFloat(char *chr);
    float FourBytesToFloat(QByteArray datas);
    float StringToFloat(QByteArray str);

    //CRC8的生成多项式：0x31(0x131)
    char CRC8_8(char chr);//CRC-8校验8位数据，生成8位校验码
    char CRC8_32(char *chr);//CRC-8校验32位数据，生成8位的校验码
    char CRC8Table_32(char *chr);//利用CRC8校验码生成表生成32位数据的校验码

public:
    //0x00~0xff的CRC8（0x31）校验码表
            char CRC8Table[256]={
            0x00,0x31,0x62,0x53,128-0xc4,128-0xf5,128-0xa6,128-0x97,128-0xb9,128-0x88,128-0xdb,128-0xea,0x7d,0x4c,0x1f,0x2e,
            0x43,0x72,0x21,0x10,128-0x87,128-0xb6,128-0xe5,128-0xd4,128-0xfa,128-0xcb,128-0x98,128-0xa9,0x3e,0x0f,0x5c,0x6d,
            128-0x86,128-0xb7,128-0xe4,128-0xd5,0x42,0x73,0x20,0x11,0x3f,0x0e,0x5d,0x6c,128-0xfb,128-0xca,128-0x99,128-0xa8,
            128-0xc5,128-0xf4,128-0xa7,128-0x96,0x01,0x30,0x63,0x52,0x7c,0x4d,0x1e,0x2f,128-0xb8,128-0x89,128-0xda,128-0xeb,
            0x3d,0x0c,0x5f,0x6e,128-0xf9,128-0xc8,128-0x9b,128-0xaa,128-0x84,128-0xb5,128-0xe6,128-0xd7,0x40,0x71,0x22,0x13,
            0x7e,0x4f,0x1c,0x2d,128-0xba,128-0x8b,128-0xd8,128-0xe9,128-0xc7,128-0xf6,128-0xa5,128-0x94,0x03,0x32,0x61,0x50,
            128-0xbb,128-0x8a,128-0xd9,128-0xe8,0x7f,0x4e,0x1d,0x2c,0x02,0x33,0x60,0x51,128-0xc6,128-0xf7,128-0xa4,128-0x95,
            128-0xf8,128-0xc9,128-0x9a,128-0xab,0x3c,0x0d,0x5e,0x6f,0x41,0x70,0x23,0x12,128-0x85,128-0xb4,128-0xe7,128-0xd6,
            0x7a,0x4b,0x18,0x29,128-0xbe,128-0x8f,128-0xdc,128-0xed,128-0xc3,128-0xf2,128-0xa1,128-0x90,0x07,0x36,0x65,0x54,
            0x39,0x08,0x5b,0x6a,128-0xfd,128-0xcc,128-0x9f,128-0xae,128-0x80,128-0xb1,128-0xe2,128-0xd3,0x44,0x75,0x26,0x17,
            128-0xfc,128-0xcd,128-0x9e,128-0xaf,0x38,0x09,0x5a,0x6b,0x45,0x74,0x27,0x16,128-0x81,128-0xb0,128-0xe3,128-0xd2,
            128-0xbf,128-0x8e,128-0xdd,128-0xec,0x7b,0x4a,0x19,0x28,0x06,0x37,0x64,0x55,128-0xc2,128-0xf3,128-0xa0,128-0x91,
            0x47,0x76,0x25,0x14,128-0x83,128-0xb2,128-0xe1,128-0xd0,128-0xfe,128-0xcf,128-0x9c,128-0xad,0x3a,0x0b,0x58,0x69,
            0x04,0x35,0x66,0x57,128-0xc0,128-0xf1,128-0xa2,128-0x93,128-0xbd,128-0x8c,128-0xdf,128-0xee,0x79,0x48,0x1b,0x2a,
            128-0xc1,128-0xf0,128-0xa3,128-0x92,0x05,0x34,0x67,0x56,0x78,0x49,0x1a,0x2b,128-0xbc,128-0x8d,128-0xde,128-0xef,
            128-0x82,128-0xb3,128-0xe0,128-0xd1,0x46,0x77,0x24,0x15,0x3b,0x0a,0x59,0x68,128-0xff,128-0xce,128-0x9d,128-0xac};

};

#endif // MYMATH_H
